/*
 * Copyright (C) 2009 Show SMS open source project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.bydavy.android.showsms.model;

//~--- non-JDK imports --------------------------------------------------------

import android.os.Bundle;

public class SimpleMessage {
    //~--- static fields ------------------------------------------------------

    private static final String EXTRAS_PHONE_NUMBER = "EXTRAS_PHONE_NUMBER";
    private static final String EXTRAS_BODY         = "EXTRAS_BODY";
    private static final String EXTRAS_TIMESTAMP    = "EXTRAS_TIMESTAMP";

    //~--- fields -------------------------------------------------------------

    public String mPhoneNumber;
    public String mBody;
    public long mTimeStamp;

    //~--- constructors -------------------------------------------------------

    public SimpleMessage(String phoneNumber, String body, long timeStamp) {
        mPhoneNumber = phoneNumber;
        mBody        = body;
        mTimeStamp   = timeStamp;
    }

    //~--- methods ------------------------------------------------------------

    public static SimpleMessage constructFromBundle(Bundle bundle) {
        String phoneNumber = bundle.getString(EXTRAS_PHONE_NUMBER);
        String body        = bundle.getString(EXTRAS_BODY);
        long timeStamp     = bundle.getLong(EXTRAS_TIMESTAMP);

        return new SimpleMessage(phoneNumber, body, timeStamp);
    }

    public Bundle toBundle() {
        Bundle b = new Bundle();

        b.putString(EXTRAS_PHONE_NUMBER, mPhoneNumber);
        b.putString(EXTRAS_BODY, mBody);
        b.putLong(EXTRAS_TIMESTAMP, mTimeStamp);

        return b;
    }

    public String toString() {
        StringBuffer buff = new StringBuffer("phoneNumber: " + mPhoneNumber);

        buff.append(", timestamp: " + mTimeStamp);
        buff.append(", body: " + mBody);

        return buff.toString();
    }
}
